home *** CD-ROM | disk | FTP | other *** search
/ Champak 50 / Volume 50 - JOGO DISK .iso / Games / mallcrawl.swf / scripts / __Packages / Twin.as < prev    next >
Encoding:
Text File  |  2007-09-28  |  3.7 KB  |  135 lines

  1. class Twin extends MovieClip
  2. {
  3.    var twin_points;
  4.    var movement;
  5.    var onEnterFrame;
  6.    var resting_position;
  7.    var is_available;
  8.    var follower;
  9.    var Char;
  10.    var randSpot;
  11.    var RUN_AWAY_SPEED = 8.5;
  12.    var RUN_AWAY_TIMER = 10;
  13.    function Twin()
  14.    {
  15.       super();
  16.       _global[this._name] = this;
  17.       _global.MallCrawl.twinsArray.push(this);
  18.       this.twin_points = 50;
  19.       this._xscale = 45;
  20.       this._yscale = 45;
  21.       this.movement = [];
  22.       this.cacheAsBitmap = true;
  23.       this.getNewSpot();
  24.       this.sendToSpot();
  25.       this.onEnterFrame = this.defaultEnterFrame;
  26.       this.gotoAndStop("still");
  27.    }
  28.    function defaultEnterFrame()
  29.    {
  30.       this._x = _level0.Background._x + this.resting_position.x;
  31.       this.is_available = true;
  32.    }
  33.    function fadeAlpha(amt)
  34.    {
  35.       this._alpha = amt;
  36.       this.follower.fadeAlpha(this._alpha);
  37.       return this._alpha;
  38.    }
  39.    function fillMovement()
  40.    {
  41.       var _loc3_ = 0;
  42.       while(_loc3_ < _global.MallCrawl.FOLLOWER_DISTANCE)
  43.       {
  44.          this.movement.push({x:this._x,y:this._y - _global.Rescuer.HEIGHT_MINUS,scale:this._xscale,moving:this.Char._currentframe > 1});
  45.          if(this.movement.length > _global.MallCrawl.FOLLOWER_DISTANCE)
  46.          {
  47.             this.follower.twinMovement(this.movement.popFirst());
  48.          }
  49.          _loc3_ = _loc3_ + 1;
  50.       }
  51.       this.follower.fillMovement();
  52.    }
  53.    function addFollower(mc)
  54.    {
  55.       mc.onEnterFrame = function()
  56.       {
  57.          this._alpha = _global.Rescuer._alpha;
  58.       };
  59.       mc.gotoAndStop("walk");
  60.       _global.MallCrawl.tcounterArray.push(mc);
  61.       this.follower = _global.MallCrawl.twinsArray.popByName(mc);
  62.       this.follower.movement = new Array();
  63.    }
  64.    function getNewSpot()
  65.    {
  66.       this.randSpot = _global.MallCrawl.randomTwinSpots.popById(random(_global.MallCrawl.randomTwinSpots.length - 1));
  67.    }
  68.    function twinMovement(obj)
  69.    {
  70.       if(obj.moving)
  71.       {
  72.          this.Twin.gotoAndStop("walk");
  73.       }
  74.       else
  75.       {
  76.          this.Twin.gotoAndStop("still");
  77.       }
  78.       this._x = obj.x;
  79.       this._y = obj.y + (_global.Rescuer._height - this._height);
  80.       if(obj.scale < 0)
  81.       {
  82.          this._xscale <= 0 ? null : (this._xscale *= -1);
  83.       }
  84.       else
  85.       {
  86.          this._xscale >= 0 ? null : (this._xscale *= -1);
  87.       }
  88.       if(this.follower)
  89.       {
  90.          this.movement.push(obj);
  91.          if(this.movement.length > _global.MallCrawl.FOLLOWER_DISTANCE)
  92.          {
  93.             this.follower.twinMovement(this.movement.popFirst());
  94.          }
  95.       }
  96.    }
  97.    function runAway(parent)
  98.    {
  99.       _global.MallCrawl.twinsArray.push(parent.follower);
  100.       parent.follower = undefined;
  101.       this.Twin.gotoAndStop("walk");
  102.       this.is_available = false;
  103.       while(this.movement.length)
  104.       {
  105.          this.movement.pop();
  106.       }
  107.       this.movement = new Array();
  108.       this._alpha = 100;
  109.       this._y = _global.MallCrawl["GLevel" + _global.Rescuer.glevel]._y - this._height;
  110.       var d = random(2);
  111.       d != 0 ? null : (d = -1);
  112.       var birth = getTimer();
  113.       this.onEnterFrame = function()
  114.       {
  115.          if(getTimer() < birth + this.RUN_AWAY_TIMER * 1000)
  116.          {
  117.             this._x += this.RUN_AWAY_SPEED * d;
  118.          }
  119.          else
  120.          {
  121.             this.getNewSpot();
  122.             this.sendToSpot();
  123.             this.onEnterFrame = this.defaultEnterFrame;
  124.          }
  125.       };
  126.    }
  127.    function sendToSpot()
  128.    {
  129.       this._x = this.randSpot._x;
  130.       this._y = this.randSpot._y;
  131.       this.resting_position = {x:this._x,y:this._y};
  132.       this.Twin.gotoAndStop("still");
  133.    }
  134. }
  135.